﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace B15_Lamda
{
    class Program
    {
        public delegate void DelOne();
        public delegate void DelTwo(string name);
        public delegate string DelThree(string name);
        static void Main(string[] args)
        {
            DelOne del1 = () => { };//delegate () { };

            DelTwo del2 = (string name) => { };//delelgate (string name){};

            DelThree del3 = (string name) => { return name; }; //delelgate(string name){ return name };

            List<int> nums = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            nums.RemoveAll(n => n > 4);

            for (int i= 0; i < nums.Count; ++i){

                Console.WriteLine(nums[i]);
            }

            Console.ReadKey();
        }
        //示例1,使用线程
        private void button1_Click(object sender, EventArgs e)
        {
            //csharp 1.0
            //使用委托，使用已定义好的函数
            new Thread(new ThreadStart(MyFun)).Start();
            //csharp 2.0
            //省略委托：MyFun自动实例化为ThreadStart委托（
            new Thread(MyFun).Start();
            //匿名方法
            new Thread(new ThreadStart(delegate () { Console.Write("my function"); })).Start();
            //匿名方法，省略参数列表
            new Thread(new ThreadStart(delegate { Console.Write("my function"); })).Start();
            //匿名方法，自动转委托
            new Thread(delegate () { Console.Write("my function"); }).Start();
            //csharp 3.0
            //Lambda表达式
            new Thread(() => { Console.Write("my function"); }).Start();
        }

        void MyFun()
        {
            Console.Write("my function");
        }
    }
}
